/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package service.views;

import com.openbrew.openbrewrf.views.FGIView;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import service.AbstractFacade;

/**
 *
 * @author chapmand
 */
@Stateless
@Path("com.openbrew.openbrewrf.fgiview")
public class FGIViewFacadeREST extends AbstractFacade<FGIView> {
    @PersistenceContext(unitName = "com.openBrew_openBrewRF_war_1.0PU")
    private EntityManager em;

    public FGIViewFacadeREST() {
        super(FGIView.class);
    }

    @GET
    @Path("{id}")
    @Produces({"application/xml", "application/json"})
    public FGIView find(@PathParam("id") Integer id) {
        getEntityManager().flush();
        FGIView fgi = super.find(id);
        getEntityManager().refresh(fgi);
        return fgi;
    }

    @GET
    @Override
    @Produces({"application/xml", "application/json"})
    public List<FGIView> findAll() {
        getEntityManager().flush();
        List<FGIView> fgis = super.findAll();
        for(FGIView fgi : fgis){
            getEntityManager().refresh(fgi);
        }
        return fgis;
    }

    @PUT
    @Override
    @Consumes({"application/xml", "application/json"})
    public void edit(FGIView entity) {
        super.edit(entity);
    }

    @GET
    @Path("{from}/{to}")
    @Produces({"application/xml", "application/json"})
    public List<FGIView> findRange(@PathParam("from") Integer from, @PathParam("to") Integer to) {
        return super.findRange(new int[]{from, to});
    }
    
    @GET
    @Path("runNamedQuery/{str}")
    @Override
    @Produces({"application/xml", "application/json"})
    public List<FGIView> runNamedQuery(@PathParam("str") String str){
        return super.runNamedQuery(str);
    }

    @GET
    @Path("count")
    @Produces("text/plain")
    public String countREST() {
        return String.valueOf(super.count());
    }

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }
    
    @GET
    @Path("runQuery/{str}")
    @Override
    @Produces({"application/xml", "application/json"})
    public List<FGIView> runQuery(@PathParam("str") String str){
        return super.runQuery(str);
    }
}
